package ar.com.spsolutions.splibrary.services.dto;

import java.util.Iterator;

import ar.com.spsolutions.splibrary.author.Author;
import ar.com.spsolutions.splibrary.services.AuthorService;

public class CRUDAuthorDTO extends AbstractCRUDDTO<Author> {

	private static final long serialVersionUID = 1783211310681870394L;
	private static final String NAME = "name";

	@Override
	public int allResultsSize() {
		return this.getAuthorService().sizeOfSearch(this.getSearchValue());
	}

	private AuthorService getAuthorService() {
		return this.getLibraryServiceFacade().getEntityService()
				.getAuthorService();
	}

	@Override
	public Iterator<? extends Author> getResults(final String searchValue,
			final int first, final int count) {
		return this.getAuthorService().getResults(searchValue, first, count)
				.iterator();
	}

	@Override
	public String getRenderPropertyFor(final String id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	protected Author getNewEntity() {
		return new Author();
	}

	@Override
	protected void setPrimaryKeyInNewEntity(final Author entity,
			final String primaryKey) {
		entity.setName(primaryKey);
	}

	@Override
	protected void update(final Author author) {
		this.getLibraryServiceFacade().update(author);
	}

	@Override
	protected void save(final Author author) {
		this.getLibraryServiceFacade().add(author);

	}

	@Override
	public void delete(final Author author) {
		this.getLibraryServiceFacade().deleted(author);
	}

	public String getName() {
		return this.getPropertyValue(CRUDAuthorDTO.NAME);
	}

	public void setName(final String aName) {
		this.setPropertyValue(CRUDAuthorDTO.NAME, aName);
	}

}
